/*
 *   Licensed to the Apache Software Foundation (ASF) under one
 *   or more contributor license agreements.  See the NOTICE file
 *   distributed with this work for additional information
 *   regarding copyright ownership.  The ASF licenses this file
 *   to you under the Apache License, Version 2.0 (the
 *   "License"); you may not use this file except in compliance
 *   with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing,
 *   software distributed under the License is distributed on an
 *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *   KIND, either express or implied.  See the License for the
 *   specific language governing permissions and limitations
 *   under the License.
 *
 */
package org.apache.directory.studio.persistence.core;


import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.ArrayUtils;


/**
 * This is a Enum to keep track of Cardinality of an attribute
 *
 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
 */
public enum Cardinality
{
    ZERO_OR_ONE,

    ONE,

    ZERO_OR_MANY_SET,

    ZERO_OR_MANY_LIST,

    ZERO_OR_MANY_ARRAY,

    ONE_OR_MANY_SET,

    ONE_OR_MANY_LIST,

    ONE_OR_MANY_ARRAY;

    /**
     * Check if the given cardinality is of the type array
     * 
     * @param cardinality the cardinality of an attribute
     * @return true if the given cardinality is of the type array
     *         if not false
     */
    public static boolean isArray( Cardinality cardinality )
    {
        if ( cardinality == Cardinality.ONE_OR_MANY_ARRAY || cardinality == Cardinality.ZERO_OR_MANY_ARRAY )
        {
            return true;
        }
        else
            return false;
    }


    /**
     * Check if the given cardinality is of the type Set
     *
     * @param cardinality the cardinality of an entry
     * @return true if the given cardinality is of the type Set
     *         if not false
     */
    public static boolean isSet( Cardinality cardinality )
    {
        if ( cardinality == Cardinality.ONE_OR_MANY_SET || cardinality == Cardinality.ZERO_OR_MANY_SET )
        {
            return true;
        }
        else
            return false;
    }


    /**
     * Check if the given cardinality is of the type List
     *
     * @param cardinality the cardinality of an entry
     * @return true if the given cardinality is of the type List
     *         if not false
     */
    public static boolean isList( Cardinality cardinality )
    {
        if ( cardinality == Cardinality.ONE_OR_MANY_LIST || cardinality == Cardinality.ZERO_OR_MANY_LIST )
        {
            return true;
        }
        else
            return false;
    }


    public static String[] getStrings()
    {
        List<String> strings = new ArrayList<String>();
        for ( Cardinality value : values() )
        {
            strings.add( value.toString() );
        }
        return strings.toArray( ArrayUtils.EMPTY_STRING_ARRAY );
    }
}
